package play.collection

const val POINTS_X_PASS: Int = 15
val EZPassAccounts: MutableMap<Int, Int> = mutableMapOf(1 to 100, 2 to 100, 3 to 100)
val EZPassReport: Map<Int, Int> = EZPassAccounts

fun updatePointsCredit(accountId: Int) {
    if (EZPassAccounts.containsKey(accountId)) {
        println("Updating $accountId...")
        EZPassAccounts[accountId] = EZPassAccounts.getValue(accountId) + POINTS_X_PASS
    } else {
        println("Error: Trying to update a non-existing account (id: $accountId)")
    }
}

fun accountsReport() {
    println("EZ-Pass report:")
    EZPassReport.forEach { (k, v) -> println("ID $k: credit $v") }
}

fun testMap() {
    accountsReport()
    updatePointsCredit(1)
    updatePointsCredit(1)
    updatePointsCredit(5)
    accountsReport()

    println(1 to 3)
    println('a' to 3)
}

fun testMap2() {
    val m = mutableMapOf("name" to "zing")
    fun test(m: MutableMap<String, String>?) {
        println(m?.get("name"))
//        println(m?.get("msg") as String)
        println(m?.get("msg").run { "hello" })
    }
    test(m)
}

fun main() {
    testMap2()
}